<?php
class fungsi{
	function __construct(){
	
	}
	
	function konek(){
		$konek = mysql_connect('localhost','root','');
		if(!$konek){
			die('tidak bisa konek' .mysql_error());
		} else{
			mysql_select_db('ngalam');
			} 
	}
	
	function session(){
		session_start();
		if (isset($_SESSION['username'])){
			header('Location: test.php');
		}
	}
	
	function info(){
			$sql = "select * from informasi_malang";
			$hasil = mysql_query($sql);
			return $hasil;		
	}
	
	function produk(){
		$konek = mysql_connect('localhost','root');
		if(!$konek){
			die('tidak bisa konek' .mysql_error());
		} else{
			mysql_select_db('ngalam');
			$sql = "SELECT A.nama, A.email, P.nama_produk, P.deskripsi_produk, P.gambar 
						FROM produk AS P, profil_akun AS A
						WHERE P.kode_akun = A.id_akun";
			$hasil = mysql_query($sql);
			return $hasil;
			}
	}
		
	function admin(){
		session_start();
		$konek = mysql_connect('localhost','root');
		if(!$konek){
			die('tidak bisa konek' .mysql_error());
		} else{
			if(isset($_SESSION['username'])){
				$tampil = '<li><a href="#">Produk Kami</a></li>
								<li><a href="#">Info Malang</a></li>
								<li><a href="l#">Lokasi Kuliner</a></li>
								<li><a href="#">Kritik dan Saran</a></li>';
				return $tampil;
			}
		}
	
	}
	
	function logout(){
		session_start();
		unset($_SESSION['username']);
		unset($_SESSION['hak_akses']);
		header('Location: home-guess.php');
	}
	
	function liatkomen(){
		$konek = mysql_connect('localhost','root');
		if(!$konek){
			die('tidak bisa konek' .mysql_error());
		} else{
			mysql_select_db('ngalam');
			$sql = "select nama, komentar from komentar";
			$hasil = mysql_query($sql);
			return $hasil;
	}
	}
	
	function komen($nama, $komentar){
		$konek = mysql_connect('localhost','root');
		if(!$konek){
			die('tidak bisa konek' .mysql_error());
		} else{
			mysql_select_db('ngalam');
			$sql = 'insert into komentar (id_komen, nama, komentar) values ("","'.$nama.'","'.$komentar.'")';
			$hasil = mysql_query($sql);
			return $hasil;
	}
	}
	
	function redirectPage ($page) {
	   $newpage = "<script type='text/javascript'>";
	   $newpage .= "window.location.href='$page';";
	   $newpage .= "</script>";
	   $newpage .= "<noscript>";
	   $newpage .= "<meta http-equiv='refresh' content='0;url=$page'/>";
	   $newpage .= "</noscript>";
		return $newpage;
	}

	}
?>